package com.zhdl.modules.common.warn.web;

import com.zhdl.common.util.WebResult;
import com.zhdl.modules.common.warn.entity.WarnRecords;
import com.zhdl.modules.common.warn.service.WarnRecordsService;
import com.zhdl.modules.common.warn.service.dto.WarnRecordsQueryCriteria;
import com.zhdl.modules.common.warn.web.request.WarnSelectRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(path = "/warnRecords", produces = MediaType.APPLICATION_JSON_VALUE)
public class WarnRecordsController {

    @Resource
    private WarnRecordsService warnRecordsService;

    /**
     * 测试接口
     *
     * @return 测试服务是否启动
     */
    @GetMapping("/demo")
    public WebResult<String> InterfaceDebugging() {
        return WebResult.okResult("当前接口通讯正常");
    }

    /**
     * 查询所有报警记录
     *
     * @return /
     */
    @GetMapping("/findAllList")
    public WebResult<List<WarnRecords>> findAllWarnRecordsList() {
        List<WarnRecords> allWarnRecords = warnRecordsService.findAllWarnRecords();
        return WebResult.okResult(allWarnRecords);
    }


    @PostMapping("/findAllPage")
    public WebResult<Page<WarnRecords>> findAllWarnRecordsPage(@RequestBody WarnSelectRequest warnSelectRequest) {
        WarnRecordsQueryCriteria warnRecordsQueryCriteria = new WarnRecordsQueryCriteria();
        //待扩展

        Pageable pageable = PageRequest.of(warnSelectRequest.getPageNumber(), warnSelectRequest.getPageSize());
        Page<WarnRecords> allPage = warnRecordsService.findAllPage(warnRecordsQueryCriteria, pageable);
        return WebResult.okResult(allPage);
    }


}
